const BaseController = require('./base_controller.js');
const UserService = require('../../service/user_service.js');
const contentCheck = require('../../../../framework/validate/content_check.js');

class UserController extends BaseController {

    /**
     * 手机注册登陆
     */
    async phone_register() {
        // 数据校验
        let rules = {
            cloudID: 'must|string|name=代码',
            spread_openid: 'string|name=推广用户ID',
        };
        // 取得数据
        let input = this.validateData(rules);
        // 内容审核
        await contentCheck.checkTextMultiClient(input);

        let service = new UserService();
        return await service.phone_register(this._openId, input);
    }

    /**
     * 获取用户信息
     */
    async get_info() {
        let service = new UserService();
        return await service.get_info(this._openId);
    }

    /**
     * 编辑用户信息
     */
    async edit_info() {
        // 数据校验
        let rules = {
            nickname: 'must|string|min:1|max:30|name=昵称',
            realname: 'must|string|min:1|max:30|name=真实姓名',
            phone: 'must|mobile|name=手机',
            avatar: 'must|string|name=头像',
            sex: 'must|string|name=性别',
        };
        // 取得数据
        let input = this.validateData(rules);
        // 内容审核
        await contentCheck.checkTextMultiClient(input);

        let service = new UserService();
        return await service.edit_info(this._openId, input);
    }

    /**
     * 记录分享朋友圈时间
     */
    async record_share_moments_time() {
        let service = new UserService();
        return await service.record_share_moments_time(this._openId);
    }

}

module.exports = UserController;